// pages/detail/detail.js
const app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    // 样式有关的变量
    theme: "blue",
    zw: 0,
    zb: 1,
    like: false,
    collect: false,
    comment: true,

    // 数据有关的变量
    poem: {},
    choosed: [],
    state: []
  },
  change2w: function (e) {
    this.setData({
      theme: "white",
      zb: 0,
      zw: 1
    })
  },
  change2b: function (e) {
    this.setData({
      theme: "blue",
      zw: 0,
      zb: 1
    })
  },
  checkChange: function (e) {
    var temp = e.detail.value
    var tmp = temp.sort()
    this.setData({
      choosed: tmp
    })
  },
  nextSave: function () {
    let that=this
    var choosed = that.data.choosed
    if (choosed.length == 0) {
      wx.showModal({
        title:'没有选择',
        content:'点击你喜欢的句子',
        cancelColor: 'cancelColor',
        showCancel:false,
        confirmText:'好的',
        success: res => {
        }
      })
    }
    else {
      wx.navigateTo({
        url: '../save/save?poem=' +JSON.stringify(that.data.poem)  + '&choosedid=' + choosed + '&theme=' + that.data.theme
      })
    }

  },
  like: function () {
    this.setData({
      like: !this.data.like
    })
  },
  collect: function () {
    this.setData({
      collect: !this.data.collect
    })
  },
  changestate: function (e) {
    var $id = e.currentTarget.id
    var upstate = this.data.state
    upstate[$id] = !upstate[$id]
    this.setData({
      state: upstate
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var poem = JSON.parse(options.poem) 
    var state = []
    for (var i = 0; i < poem.content.length; i++) {
      state.push(false)
    }
    this.setData({
      poem: poem,
      state: state
    })
  },
  comment: function () {
    this.setData({
      comment: !this.data.comment
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})